(function (aopc) {
    aopc.addExpandPage(817, function (get) {
        const Common = get('UtilsCommon', 'Common');

        return {
            expandInit() {
                this.meeting_bg_view = this.getProperty('meeting_bg_view');
                const displayMethod = this.getProperty('DisplayMethod');
                displayMethod.getValue = () => displayMethod.selectValue || 0;
                displayMethod.setValue = this.setDisplayMethod.bind(this);
                displayMethod.properties.forEach((p, i) => {
                    p.selectValue = i
                    p.eventActionName = 'setDisplayMethodSelected'
                });
                this.displayMethod = displayMethod;

                // const startTime = this.getProperty('StartTime');
                // startTime.dataSource = [this.getHours(), this.getMinutes()];
                // const endTime = this.getProperty('EndTime');
                // endTime.dataSource = [this.getHours(), this.getMinutes()];

                this.dialog_content_edit = this.getProperty('dialog_content_edit');
                this.defaultBackImageUrl = 'images/yxinmt_h5/24111120500579060.png';
            },
            closeNotice() {
                this.webSocket.send('closeMeetingNotice');
                this.alertSuccess('关闭会议公告命令已发送！');
            },
            getHours() {
                const dataSource = [];
                for (let i = 8; i < 24; i++) {
                    const v = (i < 10 ? '0' : '') + i;
                    dataSource.push({ Value: v, Text: v });
                }
                for (let i = 0; i < 8; i++) {
                    const v = (i < 10 ? '0' : '') + i;
                    dataSource.push({ Value: v, Text: v });
                }
                return dataSource;
            },
            getMinutes() {
                const dataSource = [];
                const list = ['00', '30', '10', '15', '20', '40', '45', '50', '25', '35', '55'];
                list.forEach(v => {
                    dataSource.push({ Value: v, Text: v });
                });
                for (let i = 0; i < 60; i++) {
                    const v = (i < 10 ? '0' : '') + i;
                    if (!list.includes(v)) dataSource.push({ Value: v, Text: v });
                }
                return dataSource;
            },
            setDisplayMethodSelected({ property }) {
                this.setDisplayMethod(property.selectValue);
            },
            setSelfHide({ property, e }) {
                const ele = property.getElement();
                if (ele === e.target) property.setIsVisible(false);
            },
            setDisplayMethod(v) {
                v = v || 0;
                this.displayMethod.selectValue = v;

                this.displayMethod.properties.forEach((p, i) => {
                    const p2 = p.properties[1];
                    p2.setIsVisible(v === i);
                    if(this.theme==='red')  p.style.border = v === i ? '2rem solid #E40404' : '2rem solid #ffffff';
                    else p.style.border = v === i ? '2rem solid #2C7AD3' : '2rem solid #ffffff';
                    p.refresh();
                });
            },
            expandGetBackImageLoad({ data }) {
                this.pageData.BackImageId = data.BackImageId;
            },
            expandSetBackImageData({ entityData }) {
                entityData.MeetingId = this.pageData.MeetingId;

                return entityData;
            },
            saveBackImageCallback({ data }) {
                if (data.BackImageId) this.pageData.BackImageId = data.BackImageId;
                this.alertSuccess('保存成功！');
            },
            uploadCallback({ fileUrl, property }) {
                const entityData = {};
                entityData[property.name] = fileUrl;
                entityData.MeetingId = this.pageData.MeetingId;

                const p = property.properties[0];
                const { serviceInterface, saveServiceInterface } = p;

                let serviceName;
                let actionName;
                let url = 'MeetingBackImage';
                if (this.pageData.BackImageId) {
                    serviceName = saveServiceInterface.serviceName;
                    actionName = saveServiceInterface.actionName;
                    url += `(${this.pageData.BackImageId})`;
                }
                else {
                    serviceName = serviceInterface.serviceName;
                    actionName = serviceInterface.actionName;
                }

                this.dispatchAction(serviceName, actionName, { url, MeetingBackImage: entityData }).then(res => {
                    if (res && res.isSuccess !== false) {
                        if (res.BackImageId) this.pageData.BackImageId = res.BackImageId;
                        this.alertSuccess('保存成功！');
                    }
                });
            },
            removeImageUrl({ property, view }) {
                if (property.isLoading) return;
                const entityData = {};
                entityData[view.name] = '';
                entityData.MeetingId = this.pageData.MeetingId;

                const { saveServiceInterface } = property;

                let url = `MeetingBackImage(${this.pageData.BackImageId})`;
                const serviceName = saveServiceInterface.serviceName;
                const actionName = saveServiceInterface.actionName;

                property.isLoading = true;
                this.dispatchAction(serviceName, actionName, { url, MeetingBackImage: entityData }).then(res => {
                    if (res && res.isSuccess !== false) view.setValue('');
                    property.isLoading = false;
                });
            },
            setSelectBackImage({ property, view }) {
                this.setMeetingBackImage(view.getValue());
                this.selectBackImageUrl = view.getValue();
                if(this.theme==='red')  property.style.border = "2rem solid #E40404";
                else property.style.border = "2rem solid #2D60FA";
                view.getView().properties.forEach(p => {
                    if (p.name !== 'save' && p.name !== 'white1') {
                        const img = p.properties[1];
                        if (p.name !== view.name) {
                            img.style.border = "2rem solid #A2ABC0";
                            img.refresh();
                        }
                    }
                });
                property.refresh();
            },
            setMeetingBackImage(url) {
                this.meetingNoticeData.BackImageUrl = url;
                this.meeting_bg_view.style.backgroundImage = url
                this.meeting_bg_view.refresh();
            },
            showContentEdit() {
                const { properties } = this.dialog_content_edit.properties[0];
                this.eventActions.entityEdit.setPropertiesValue(properties, this.meetingNoticeData);
                this.dialog_content_edit.setIsVisible(true);
            },
            expandGetMeetingNoticeLoad({ data }) {
                this.meetingNoticeData = data;
                if (data.BackImageUrl) this.setMeetingBackImage(data.BackImageUrl);

                this.setContentFont(data);
            },
            setContentFont(data) {
                const p = this.meeting_bg_view.properties[0];
                p.spanStyle.color = data.FontColor;
                p.setValue(data.Content);
                p.refresh();
            },
            expandSetMeetingNoticeData({ entityData }) {
                entityData.MeetingId = this.pageData.MeetingId;
                entityData.Content = this.meetingNoticeData.Content;
                entityData.FontColor = this.meetingNoticeData.FontColor;
                entityData.BackImageUrl = this.meetingNoticeData.BackImageUrl;
                if (Common.isNullOrEmpty(entityData.Content)) {
                    this.alert('内容不能为空，请编辑内容！');
                    return false;
                }
                if (Common.isNullOrEmpty(entityData.BackImageUrl)) {
                    this.alert('请选择背景图');
                    return false;
                }
                this.noticeEntityData = entityData;
                return entityData;
            },
            saveMeetingNtoiceCallback() {
                this.alertSuccess('发布成功！');
                this.webSocket.send('sendMeetingNotice', this.noticeEntityData);
            },
            setConentOk() {
                const { properties } = this.dialog_content_edit.properties[0];
                const entityData = this.eventActions.entityEdit.getPropertyValues(properties, this);
                this.meetingNoticeData.Content = entityData.Content;
                this.meetingNoticeData.FontColor = entityData.FontColor;

                this.setContentFont(this.meetingNoticeData);
                this.dialog_content_edit.setIsVisible(false);
            }
        }
    });
})(window.aopc);